/**
* @description: 419. 甲板上的战舰
* @author hewei
* @date 2022/8/1 16:09
* @version 1.0
*/

public class CountBattleships {

    public int countBattleships(char[][] board) {
        int ans = 0;
        int m = board.length;
        int n = board[0].length;
        int[][] road = {{0, 1}, {1, 0}};
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (board[i][j] == 'X') {
                    ++ans;
                    board[i][j] = '.';
                    for (int[] ints : road) {
                        int x = i + ints[0];
                        int y = j + ints[1];
                        while (x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'X') {
                            board[x][y] = '.';
                            x += ints[0];
                            y += ints[1];
                        }
                    }
                }
            }
        }
        return ans;
    }
}
